package com.bear.fastrepair.service

import com.bear.fastrepair.utils.WEB_SOCKET_URL
import okhttp3.OkHttpClient
import okhttp3.Request
import okhttp3.WebSocket
import okhttp3.WebSocketListener
import java.util.concurrent.TimeUnit

object WebSocketHelper {
    /**
     * 创建一个WebSocket连接
     * @param employeeId String
     * @param listener WebSocketListener
     * @return WebSocket
     */
    fun createWebSocketConnection(employeeId: String, listener: WebSocketListener): WebSocket {
        val client = OkHttpClient.Builder().pingInterval(10, TimeUnit.SECONDS).build()
        val request = Request.Builder().url(WEB_SOCKET_URL + employeeId).build()
        return client.newWebSocket(request, listener)
    }
}